package com.wts.exam.service.subject.handle;

import java.util.List;

import org.apache.commons.lang.StringUtils;

import com.farm.core.auth.domain.LoginUser;
import com.farm.core.time.TimeTool;
import com.wts.exam.dao.SubjectDaoInter;
import com.wts.exam.dao.SubjectanswerDaoInter;
import com.wts.exam.dao.SubjectversionDaoInter;
import com.wts.exam.domain.PaperAnswer;
import com.wts.exam.domain.Subject;
import com.wts.exam.domain.SubjectAnswer;
import com.wts.exam.domain.SubjectVersion;
import com.wts.exam.domain.ex.AnswerUnit;
import com.wts.exam.domain.ex.SubjectUnit;
import com.wts.exam.domain.ex.TipType;
import com.wts.exam.service.SubjectServiceInter;
import com.wts.exam.service.subject.SubjectTipHandle;

/**
 * 空的逻辑处理
 * 
 * @author macpl
 *
 */
public class InterlocutionHandle implements SubjectTipHandle {

	@Override
	public void subjectInitHandle(Subject subject, SubjectVersion version, SubjectanswerDaoInter subjectanswerDaoImpl,
			SubjectDaoInter subjectDaoImpl, SubjectversionDaoInter subjectversionDaoImpl, LoginUser user) {
		// TODO 不做处理

	}

	@Override
	public SubjectUnit expressTextSubject(String subjectText, String subjectTypeId, LoginUser currentUser,
			SubjectServiceInter subjectServer, SubjectanswerDaoInter subjectanswerDaoImpl,
			SubjectDaoInter subjectDaoImpl, SubjectversionDaoInter subjectversionDaoImpl) {
		SubjectUnit unit = null;
		unit = subjectServer.initSubjectUnit(TipType.Interlocution, subjectTypeId, currentUser);
		unit.getSubject().setPstate("1");
		unit.getVersion().setTipstr(subjectText);
		subjectDaoImpl.editEntity(unit.getSubject());
		subjectversionDaoImpl.editEntity(unit.getVersion());
		// --------------------------------------------------------------------
		unit = subjectServer.getSubjectUnit(unit.getVersion().getId());
		return new SubjectUnit();
	}

	@Override
	public boolean isHaveAnswer(List<PaperAnswer> answers) {
		for (PaperAnswer answer : answers) {
			if (StringUtils.isNotBlank(answer.getValstr())) {
				return true;
			}
		}
		return false;
	}
	
	@Override
	public void loadVal(SubjectUnit nuit, List<PaperAnswer> list) {
		for(PaperAnswer val:list){
			for(AnswerUnit answer:nuit.getAnswers()){
				if(answer.getAnswer().getId().equals(val.getAnswerid())){
					
				}
			}
		}
	}
}
